home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4379 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  57 lines

  1. Path: newsfeed.internetmci.com!iol!usenet
  2. From: mat8033@iol.ie (Stuart Mc Bride)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Getting the system time and date
  5. Date: Tue, 30 Jan 1996 09:09:00 GMT
  6. Organization: Ireland On-Line
  7. Message-ID: <4ejr3d$h9q@barnacle.iol.ie>
  8. References: <tate.1.002C7F92@netwest.com> <4duk43$8ql@barnacle.iol.ie> <4e2qfg$pdr@locutus.rchland.ibm.com>
  9. NNTP-Posting-Host: dialup-186.dublin.iol.ie
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. pstaite@vnet.ibm.com wrote:
  13.  
  14. >In <4duk43$8ql@barnacle.iol.ie>, mat8033@iol.ie (Stuart Mc Bride) writes:
  15. >>tate@netwest.com (Tate Griffin) wrote:
  16. >>
  17. >>>How do I get the current time and date from a PC using C++?
  18. >>
  19.  
  20. >Wow that was complicated, why not just use this (which will work on most
  21. >systems, not just the PC):
  22.  
  23. >#include<iostream.h>
  24. >#include<time.h>
  25.  
  26. >int main() {
  27. >    cout << ctime( time( 0 ) ) << endl;
  28. >    return 0; }
  29.  
  30.  
  31. >Phil Staite, team OS/2
  32. >internet: pstaite@vnet.ibm.com  internal: pstaite@rchland
  33.  
  34. Okay, so that's shorter, but I'd hardly call my way complicated.
  35. What's more, it may be just me, but that won't work in BC++3.1
  36.  
  37. This however will:
  38.  
  39. #include <stdio.h>
  40. #include <time.h>
  41.  
  42. int main()
  43. {
  44.     time_t t;
  45.     time(&t);
  46.     printf("Today's date and time: %s\n",ctime(&t));
  47.     return 0;
  48. }
  49.  
  50. --- Stuart ---    mat8033@iol.ie
  51.                   c2smcbri@compapp.dcu.ie
  52.  
  53.    http://www.compapp.dcu.ie/~c2smcbri
  54.  
  55. - Gross Incompetence = 144 Computer Programmers -
  56.  
  57.